package orderoid.soap.business;

import orderoid.soap.Tool.DeserialisationTool;
import orderoid.soap.classeCommune.Client;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.AsyncTask;
import android.util.Log;

public class webServiceModifierClient extends AsyncTask<String, Void, Client> {

	private static final String PARAM_IDCLIENT = "idClient";
	private static final String PARAM_NOM = "nom";
	private static final String PARAM_PRENOM = "prenom";
	private static final String PARAM_CIV = "civilite";
	private static final String PARAM_TEL = "telephone";
	private static final String PARAM_EMAIL = "email";
	private static final String PARAM_ADRESSE = "adresse";
	private static final String PARAM_ADR_COMPL = "adresseComplement";
	private static final String PARAM_CODE_POSTAL = "codePostal";
	private static final String PARAM_VILLE = "ville";
	private static final String PARAM_PWD = "password";
	
	@Override
	protected Client doInBackground(String... params) {
		Log.e("Test", "doInBackground : WebService modification d'inscription");
		
		String idClient = params[0];
		String nom = params[1];
    	String prenom = params[2];
    	String tel = params[3];
    	String mail = params[4];
    	String adresse = params[5];
    	String complement = params[6];
    	String codepost = params[7];
    	String ville = params[8];
    	String inscriptionPassword = params[9];
    	String civilite = params[10];

		SoapObject request = new SoapObject(
				orderoid.soap.constant.method.NAMESPACE,
				orderoid.soap.constant.method.METHOD_NAME_MODIFIER);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);

		envelope.setOutputSoapObject(request);

		HttpTransportSE androidHttpTransport = new HttpTransportSE(
				orderoid.soap.constant.method.URL);

		request.addProperty(PARAM_IDCLIENT, idClient);
		request.addProperty(PARAM_NOM, nom);
		request.addProperty(PARAM_PRENOM, prenom);
		request.addProperty(PARAM_TEL, tel);
		request.addProperty(PARAM_EMAIL, mail);
		request.addProperty(PARAM_ADRESSE, adresse);
		request.addProperty(PARAM_ADR_COMPL, complement);
		request.addProperty(PARAM_CODE_POSTAL, codepost);
		request.addProperty(PARAM_VILLE, ville);
		request.addProperty(PARAM_PWD, inscriptionPassword);
		request.addProperty(PARAM_CIV, civilite);

		Client client = new Client();
		try {
			androidHttpTransport.call(
					orderoid.soap.constant.method.SOAP_ACTION_MODIFIER,
					envelope);

			SoapObject soapObjectResp = (SoapObject) envelope.getResponse();

			client = DeserialisationTool.deserialisationClient(soapObjectResp);

		} catch (Exception e) {
			Log.e("Erreur", e.getMessage());
			client = null;
		}
		return client;
	}

}
